package routes

import (
	"gin-AssetManagement/controllers"
	_ "gin-AssetManagement/docs"
	"github.com/gin-gonic/gin"
)

func GinRoute() *gin.Engine {
	r := RouteInit()
	// /login 路由在中间件前面所以他不受权限控制
	r.GET("/login", controllers.LoginView)
	r.POST("/login", controllers.Login)
	r.GET("/logout", controllers.Logout)
	r.GET("/admin/desktop/index", controllers.Desktop)
	//测试上传
	r.POST("/upload", controllers.Upload)
	// 加载中间件AuthMiddleware做权限认证
	r.Use(controllers.AuthMiddleware())
	r.GET("/home/index", controllers.Home)
	userGroup := r.Group("/users")
	{
		userGroup.GET("/index", controllers.UsersView)
		//userGroup.GET("/getUsers", controllers.GetUserBasic)
		userGroup.GET("/getRole", controllers.GetRoles)
		userGroup.GET("/create", controllers.CreateUserView)
		userGroup.POST("/create", controllers.CreateUser)
		userGroup.GET("/lists", controllers.UsersList)
		userGroup.GET("/edit", controllers.EditUsersView)
		userGroup.POST("/edit/:id", controllers.EditUsers)
		userGroup.GET("/del/:id", controllers.DelUsers)
		userGroup.GET("/reset/:id", controllers.UsersResetPassword)
	}
	menusGroup := r.Group("/menus")
	{
		menusGroup.GET("/index", controllers.MenusView)
		menusGroup.GET("/lists", controllers.MenusList)
		menusGroup.GET("/createMenus", controllers.CreateMenusView)
		menusGroup.POST("/createMenus", controllers.CreateMenus)
		menusGroup.GET("/del/:id", controllers.DelMenus)
		menusGroup.GET("/menusTreeList", controllers.GetMenusTreeList)
		menusGroup.POST("/update/:id", controllers.UpdateMenus)
	}
	rolesGroup := r.Group("/roles")
	{
		rolesGroup.GET("/index", controllers.RolesView)
		rolesGroup.GET("/lists", controllers.RolesList)
		rolesGroup.GET("/create", controllers.CreateRolesView)
		rolesGroup.POST("create", controllers.CreateRoles)
		rolesGroup.GET("/edit", controllers.EditROlesView)
		rolesGroup.GET("/edit/treelist/:id", controllers.EditRolesTreeList)
		rolesGroup.POST("/edit/:id", controllers.EditRoles)
		rolesGroup.GET("/del/:id", controllers.DelRoles)
	}
	return r
}
